IdeaBlade.EntityModel Assembly > IdeaBlade.EntityModel Namespace > EntityQueryExtensions Class > Filter Method : Filter<TQuery>(TQuery,EntityQueryFilterCollection) Method |
'Declaration
<ExtensionAttribute()> Public Overloads Shared Function Filter(Of TQuery As ITypedEntityQuery)( _ ByVal query As TQuery, _ ByVal filters As EntityQueryFilterCollection _ ) As TQuery
'Usage
Dim query As TQuery Dim filters As EntityQueryFilterCollection Dim value As TQuery value = EntityQueryExtensions.Filter(Of TQuery)(query, filters)
[Extension()] public static TQuery Filter<TQuery>( TQuery query, EntityQueryFilterCollection filters ) where TQuery: ITypedEntityQuery
The Filter is most useful in appending to an existing query on the server prior to execution, where you cannot easily modify the query expression provided. The query may also be filtered on the client using the Querying event.
Note that Filter returns a new query with the filter(s) added; the original query is not modified.
public void FilteringSample() { // Query for all customers. A filter will be applied prior to execution. var mgr = new DomainModelEntityManager(); mgr.Querying += new EventHandler<EntityQueryingEventArgs>(mgr_Querying); var list = mgr.Customers.ToList(); } // Client-side filtering in the EM.Querying event handler private void mgr_Querying(object sender, EntityQueryingEventArgs e) { EntityQueryFilterCollection clientFilters = new EntityQueryFilterCollection(); clientFilters.AddFilter<Customer>(q => q.Where(c => c.Country == "UK")); e.Query = e.Query.Filter(clientFilters); }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2